﻿using System.Web.Mvc;
using DiNinject.Repository.Interfaces;
using DiNinject.Web.UI.Models.Autos;
using Ninject;

namespace DiNinject.Web.UI.Controllers
{
    public class AutoController : Controller
    {
        #region Injections
        [Inject]
        public IAutoRespository AutoRespository { protected get; set; }
        #endregion

        #region View Functions
        public ActionResult AutoList()
        {
            AutoListModel model = new AutoListModel();
            model.Load(AutoRespository);
            return View("AutoList", "Auto", model);
        }

        public ActionResult AutoView(int id)
        {
            AutoViewModel model = new AutoViewModel();
            model.Load(id, AutoRespository);
            return View("AutoView", "Auto", model);
        }

        public ActionResult AutoEdit(int id)
        {
            AutoEditModel model = new AutoEditModel();
            model.Load(id, AutoRespository);
            return View("AutoEdit", "Auto", model);
        }

        [HttpPost]
        public ActionResult AutoSave(AutoEditModel model)
        {
            if (ModelState.IsValid)
            {
                model.SaveOrUpdate(AutoRespository);
                RedirectToAction("AutoView", "Auto", new {id = model.Id});
            }

            return View();
        }
        #endregion
    }
}